package com.stx.design.observer;

import java.util.ArrayList;
import java.util.List;

public class RealSubject implements Subject{

	private List<Observer> observerList;
	
	public RealSubject(){
		observerList = new ArrayList<Observer>();
	}
	
	@Override
	public void attach(Observer observer) {
		if(observer != null){
			observerList.add(observer);
		}else{
			System.out.println("attach observer is null...");
		}
	}

	@Override
	public void detach(Observer observer) {
		if(observer != null){
			observerList.remove(observer);
		}else{
			System.out.println("detach observer is null...");
		}
	}

	@Override
	public void notifyChanged() {
		for(Observer ob : observerList){
			ob.update();
		}
	}

}
